home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / syntax / c.vim < prev    next >
Encoding:
Text File  |  2001-09-03  |  14.9 KB  |  317 lines

  1. " Vim syntax file
  2. " Language:    C
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last Change:    2001 Sep 03
  5.  
  6. " For version 5.x: Clear all syntax items
  7. " For version 6.x: Quit when a syntax file was already loaded
  8. if version < 600
  9.   syntax clear
  10. elseif exists("b:current_syntax")
  11.   finish
  12. endif
  13.  
  14. " A bunch of useful C keywords
  15. syn keyword    cStatement    goto break return continue asm
  16. syn keyword    cLabel        case default
  17. syn keyword    cConditional    if else switch
  18. syn keyword    cRepeat        while for do
  19.  
  20. syn keyword    cTodo        contained TODO FIXME XXX
  21.  
  22. " cCommentGroup allows adding matches for special things in comments
  23. syn cluster    cCommentGroup    contains=cTodo
  24.  
  25. " String and Character constants
  26. " Highlight special characters (those which have a backslash) differently
  27. syn match    cSpecial    display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)"
  28. if !exists("c_no_utf")
  29.   syn match    cSpecial    display contained "\\\(u\x\{4}\|U\x\{8}\)"
  30. endif
  31. if exists("c_no_cformat")
  32.   syn region    cString        start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
  33.   " cCppString: same as cString, but ends at end of line
  34.   syn region    cCppString    start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial
  35. else
  36.   syn match    cFormat        display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([diuoxXfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  37.   syn match    cFormat        display "%%" contained
  38.   syn region    cString        start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat
  39.   " cCppString: same as cString, but ends at end of line
  40.   syn region    cCppString    start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat
  41. endif
  42.  
  43. syn match    cCharacter    "L\='[^\\]'"
  44. syn match    cCharacter    "L'[^']*'" contains=cSpecial
  45. if exists("c_gnu")
  46.   syn match    cSpecialError    "L\='\\[^'\"?\\abefnrtv]'"
  47.   syn match    cSpecialCharacter "L\='\\['\"?\\abefnrtv]'"
  48. else
  49.   syn match    cSpecialError    "L\='\\[^'\"?\\abfnrtv]'"
  50.   syn match    cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
  51. endif
  52. syn match    cSpecialCharacter display "L\='\\\o\{1,3}'"
  53. syn match    cSpecialCharacter display "'\\x\x\{1,2}'"
  54. syn match    cSpecialCharacter display "L'\\x\x\+'"
  55.  
  56. "when wanted, highlight trailing white space
  57. if exists("c_space_errors")
  58.   if !exists("c_no_trail_space_error")
  59.     syn match    cSpaceError    display excludenl "\s\+$"
  60.   endif
  61.   if !exists("c_no_tab_space_error")
  62.     syn match    cSpaceError    display " \+\t"me=e-1
  63.   endif
  64. endif
  65.  
  66. "catch errors caused by wrong parenthesis and brackets
  67. syn cluster    cParenGroup    contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  68. if exists("c_no_bracket_error")
  69.   syn region    cParen        transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString
  70.   " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  71.   syn region    cCppParen    transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString
  72.   syn match    cParenError    display ")"
  73.   syn match    cErrInParen    display contained "[{}]"
  74. else
  75.   syn region    cParen        transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString
  76.   " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  77.   syn region    cCppParen    transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString
  78.   syn match    cParenError    display "[\])]"
  79.   syn match    cErrInParen    display contained "[\]{}]"
  80.   syn region    cBracket    transparent start='\[' end=']' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString
  81.   " cCppBracket: same as cParen but ends at end-of-line; used in cDefine
  82.   syn region    cCppBracket    transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString
  83.   syn match    cErrInBracket    display contained "[);{}]"
  84. endif
  85.  
  86. "integer number, or floating point number without a dot and with "f".
  87. syn case ignore
  88. syn match    cNumbers    display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
  89. " Same, but without octal error (for comments)
  90. syn match    cNumbersCom    display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
  91. syn match    cNumber        display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  92. "hex number
  93. syn match    cNumber        display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
  94. " Flag the first zero of an octal number as something special
  95. syn match    cOctal        display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  96. syn match    cOctalZero    display contained "\<0"
  97. syn match    cFloat        display contained "\d\+f"
  98. "floating point number, with dot, optional exponent
  99. syn match    cFloat        display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
  100. "floating point number, starting with a dot, optional exponent
  101. syn match    cFloat        display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  102. "floating point number, without dot, with exponent
  103. syn match    cFloat        display contained "\d\+e[-+]\=\d\+[fl]\=\>"
  104. " flag an octal number with wrong digits
  105. syn match    cOctalError    display contained "0\o*[89]\d*"
  106. syn case match
  107.  
  108. if exists("c_comment_strings")
  109.   " A comment can contain cString, cCharacter and cNumber.
  110.   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  111.   " need to use a special type of cString: cCommentString, which also ends on
  112.   " "*/", and sees a "*" at the start of the line as comment again.
  113.   " Unfortunately this doesn't very well work for // type of comments :-(
  114.   syntax match    cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  115.   syntax region cCommentString    contained start=+L\="+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  116.   syntax region cComment2String    contained start=+L\="+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  117.   syntax region  cCommentL    start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError
  118.   syntax region cComment    matchgroup=cCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError
  119. else
  120.   syn region    cCommentL    start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError
  121.   syn region    cComment    matchgroup=cCommentStart start="/\*" matchgroup=NONE end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError
  122. endif
  123. " keep a // comment separately, it terminates a preproc. conditional
  124. syntax match    cCommentError    display "\*/"
  125. syntax match    cCommentStartError display "/\*"me=e-1 contained
  126.  
  127. syn keyword    cOperator    sizeof
  128. if exists("c_gnu")
  129.   syn keyword    cStatement    __asm__
  130.   syn keyword    cOperator    typeof __real__ __imag__
  131. endif
  132. syn keyword    cType        int long short char void
  133. syn keyword    cType        signed unsigned float double
  134. if !exists("c_no_ansi") || exists("c_ansi_typedefs")
  135.   syn keyword   cType        size_t wchar_t ptrdiff_t sig_atomic_t fpos_t
  136.   syn keyword   cType        clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t
  137.   syn keyword   cType        mbstate_t wctrans_t wint_t wctype_t
  138. endif
  139. if !exists("c_no_c99") " ISO C99
  140.   syn keyword    cType        bool complex
  141.   syn keyword    cType        int8_t int16_t int32_t int64_t
  142.   syn keyword    cType        uint8_t uint16_t uint32_t uint64_t
  143.   syn keyword    cType        int_least8_t int_least16_t int_least32_t int_least64_t
  144.   syn keyword    cType        uint_least8_t uint_least16_t uint_least32_t uint_least64_t
  145.   syn keyword    cType        int_fast8_t int_fast16_t int_fast32_t int_fast64_t
  146.   syn keyword    cType        uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
  147.   syn keyword    cType        intptr_t uintptr_t
  148.   syn keyword    cType        intmax_t uintmax_t
  149. endif
  150. if exists("c_gnu")
  151.   syn keyword    cType        __label__ __complex__ __volatile__
  152. endif
  153.  
  154. syn keyword    cStructure    struct union enum typedef
  155. syn keyword    cStorageClass    static register auto volatile extern const
  156. if exists("c_gnu")
  157.   syn keyword    cStorageClass    inline __attribute__
  158. endif
  159.  
  160. if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
  161.   if exists("c_gnu")
  162.     syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__
  163.   endif
  164.   syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__
  165.   syn keyword cConstant __STDC_VERSION__
  166.   syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
  167.   syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
  168.   syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
  169.   syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
  170.   syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
  171.   syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
  172.   syn keyword cConstant FLT_RADIX FLT_ROUNDS
  173.   syn keyword cConstant FLT_DIG FLT_MANT_DIG FLT_EPSILON
  174.   syn keyword cConstant DBL_DIG DBL_MANT_DIG DBL_EPSILON
  175.   syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON
  176.   syn keyword cConstant FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP
  177.   syn keyword cConstant FLT_MIN_10_EXP FLT_MAX_10_EXP
  178.   syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP
  179.   syn keyword cConstant DBL_MIN_10_EXP DBL_MAX_10_EXP
  180.   syn keyword cConstant LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP
  181.   syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP
  182.   syn keyword cConstant HUGE_VAL CLOCKS_PER_SEC NULL
  183.   syn keyword cConstant LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY
  184.   syn keyword cConstant LC_NUMERIC LC_TIME
  185.   syn keyword cConstant SIG_DFL SIG_ERR SIG_IGN
  186.   syn keyword cConstant SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM
  187.   " Add POSIX signals as well...
  188.   syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP
  189.   syn keyword cConstant SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  190.   syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU
  191.   syn keyword cConstant SIGUSR1 SIGUSR2
  192.   syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF
  193.   syn keyword cConstant FOPEN_MAX FILENAME_MAX L_tmpnam
  194.   syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET
  195.   syn keyword cConstant TMP_MAX stderr stdin stdout
  196.   syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  197.   " Add POSIX errors as well
  198.   syn keyword cConstant E2BIG EACCES EAGAIN EBADF EBADMSG EBUSY
  199.   syn keyword cConstant ECANCELED ECHILD EDEADLK EDOM EEXIST EFAULT
  200.   syn keyword cConstant EFBIG EILSEQ EINPROGRESS EINTR EINVAL EIO EISDIR
  201.   syn keyword cConstant EMFILE EMLINK EMSGSIZE ENAMETOOLONG ENFILE ENODEV
  202.   syn keyword cConstant ENOENT ENOEXEC ENOLCK ENOMEM ENOSPC ENOSYS
  203.   syn keyword cConstant ENOTDIR ENOTEMPTY ENOTSUP ENOTTY ENXIO EPERM
  204.   syn keyword cConstant EPIPE ERANGE EROFS ESPIPE ESRCH ETIMEDOUT EXDEV
  205.   " math.h
  206.   syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4
  207.   syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2
  208. endif
  209. if !exists("c_no_c99") " ISO C99
  210.   syn keyword cConstant true false
  211. endif
  212.  
  213. syn region    cPreCondit    start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
  214. syn match    cPreCondit    display "^\s*#\s*\(else\|endif\)\>"
  215. if !exists("c_no_if0")
  216.   syn region    cCppOut        start="^\s*#\s*if\s\+0\+\>" end=".\|$" contains=cCppOut2
  217.   syn region    cCppOut2    contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip
  218.   syn region    cCppSkip    contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=cSpaceError,cCppSkip
  219. endif
  220. syn region    cIncluded    display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  221. syn match    cIncluded    display contained "<[^>]*>"
  222. syn match    cInclude    display "^\s*#\s*include\>\s*["<]" contains=cIncluded
  223. "syn match cLineSkip    "\\$"
  224. syn cluster    cPreProcGroup    contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti
  225. syn region    cDefine        start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@cPreProcGroup
  226. syn region    cPreProc    start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup
  227.  
  228. " Highlight User Labels
  229. syn cluster    cMultiGroup    contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
  230. syn region    cMulti        transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup
  231. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  232. syn cluster    cLabelGroup    contains=cUserLabel
  233. syn match    cUserCont    display "^\s*\I\i*\s*:$" contains=@cLabelGroup
  234. syn match    cUserCont    display ";\s*\I\i*\s*:$" contains=@cLabelGroup
  235. syn match    cUserCont    display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  236. syn match    cUserCont    display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  237.  
  238. syn match    cUserLabel    display "\I\i*" contained
  239.  
  240. " Avoid recognizing most bitfields as labels
  241. syn match    cBitField    display "^\s*\I\i*\s*:\s*[1-9]"me=e-1
  242. syn match    cBitField    display ";\s*\I\i*\s*:\s*[1-9]"me=e-1
  243.  
  244. if exists("c_minlines")
  245.   let b:c_minlines = c_minlines
  246. else
  247.   if !exists("c_no_if0")
  248.     let b:c_minlines = 50    " #if 0 constructs can be long
  249.   else
  250.     let b:c_minlines = 15    " mostly for () constructs
  251.   endif
  252. endif
  253. exec "syn sync ccomment cComment minlines=" . b:c_minlines
  254.  
  255. " Define the default highlighting.
  256. " For version 5.7 and earlier: only when not done already
  257. " For version 5.8 and later: only when an item doesn't have highlighting yet
  258. if version >= 508 || !exists("did_c_syn_inits")
  259.   if version < 508
  260.     let did_c_syn_inits = 1
  261.     command -nargs=+ HiLink hi link <args>
  262.   else
  263.     command -nargs=+ HiLink hi def link <args>
  264.   endif
  265.  
  266.   HiLink cFormat        cSpecial
  267.   HiLink cCppString        cString
  268.   HiLink cCommentL        cComment
  269.   HiLink cCommentStart        cComment
  270.   HiLink cLabel            Label
  271.   HiLink cUserLabel        Label
  272.   HiLink cConditional        Conditional
  273.   HiLink cRepeat        Repeat
  274.   HiLink cCharacter        Character
  275.   HiLink cSpecialCharacter    cSpecial
  276.   HiLink cNumber        Number
  277.   HiLink cOctal            Number
  278.   HiLink cOctalZero        PreProc     " link this to Error if you want
  279.   HiLink cFloat            Float
  280.   HiLink cOctalError        cError
  281.   HiLink cParenError        cError
  282.   HiLink cErrInParen        cError
  283.   HiLink cErrInBracket        cError
  284.   HiLink cCommentError        cError
  285.   HiLink cCommentStartError    cError
  286.   HiLink cSpaceError        cError
  287.   HiLink cSpecialError        cError
  288.   HiLink cOperator        Operator
  289.   HiLink cStructure        Structure
  290.   HiLink cStorageClass        StorageClass
  291.   HiLink cInclude        Include
  292.   HiLink cPreProc        PreProc
  293.   HiLink cDefine        Macro
  294.   HiLink cIncluded        cString
  295.   HiLink cError            Error
  296.   HiLink cStatement        Statement
  297.   HiLink cPreCondit        PreCondit
  298.   HiLink cType            Type
  299.   HiLink cConstant        Constant
  300.   HiLink cCommentString        cString
  301.   HiLink cComment2String    cString
  302.   HiLink cCommentSkip        cComment
  303.   HiLink cString        String
  304.   HiLink cComment        Comment
  305.   HiLink cSpecial        SpecialChar
  306.   HiLink cTodo            Todo
  307.   HiLink cCppSkip        cCppOut
  308.   HiLink cCppOut2        cCppOut
  309.   HiLink cCppOut        Comment
  310.  
  311.   delcommand HiLink
  312. endif
  313.  
  314. let b:current_syntax = "c"
  315.  
  316. " vim: ts=8
  317.